#ifndef RSUCTRL
#define RSUCTRL

#include <QObject>
#include <QTimer>
#include "basersuctrl.h"
#include "rsuconnect.h"

class RsuTransMgr;

class RsuCtrl : public BaseRsuCtrl
{
    Q_OBJECT

public:
    explicit RsuCtrl(int id, QObject *parent = 0)
    {
        new (this) RsuCtrl(parent);
        this->setId(id);
    }

    explicit RsuCtrl(QObject *parent = 0);
    ~RsuCtrl();

    /*!
     * \brief 国标终端机编号
     */
    quint8 m_gbTermNo[6];

    ObuInfo m_currentObu;
    IccInfo m_currentIcc;

public:
    virtual void reopenRsu();

    virtual void closeRsu();

public:
    virtual int initRsu();
    virtual int getRsuInfo();
    virtual int detectObu();
    virtual void releaseObu(quint32 nMacId);
    virtual void releaseCurrentObu();
    virtual bool checkRsuStatus();
    virtual void configRsuType(const QString &rsuType);

public:
    virtual void mockRawFrameData(QByteArray &frame)
    {
        m_rsuComm.mockRawFrameData(frame);
    }

public:
    /*!
     * \brief 如果当前为正常交易状态，恢复正常交易
     */
    bool resumeNormalTrans();

    /*!
     * \brief 如果当前为正常交易状态，暂停正常交易
     */
    bool pauseNormalTrans();

public:
    bool processRsuInitFrame(const QByteArray &frame);

    bool processDecipheredFileFrame(const QByteArray &frame);

    void processRsuInfoFrame(const QByteArray &frame);
    bool processObuInitFrame(const QByteArray &frame);
    bool processObuInfo(int nProfile, int nAppList, const QByteArray &baApp, const QByteArray &baObuCfg);
    bool processGetSecureFrame(const QByteArray &frame);
//    bool getSecureRq();

protected:
    RsuConnect m_rsuComm;
    int m_nGbPsamSlot;

protected slots:
    void socketStateChanged(QAbstractSocket::SocketState socketState);
    void processRsuFrame(quint8 nFrameIndex, quint8 nFrameType, const QByteArray &frame);

protected:
    void startTransInit();
    bool getSecureRq();

public:
    void transToNormalTransStatus();

protected:
    RsuTransMgr *m_pCurrentRsuTransMgr;
    RsuTransMgr *m_pRsuTransMgrAtInitStage;
    RsuTransMgr *m_pRsuTransMgrForNormalTrans;

};

#endif // RSUCTRL

